/*
 * Copyright (c) 2010. Dylan Schell.
 */

package nl.xs4all.dylanschell.deckprinter.transform;

import com.google.inject.Inject;
import nl.xs4all.dylanschell.deckprinter.model.CardInDeck;
import nl.xs4all.dylanschell.deckprinter.model.CardInSet;
import nl.xs4all.dylanschell.deckprinter.model.DeckDescriptor;
import nl.xs4all.dylanschell.deckprinter.services.SetService;
import org.apache.wicket.injection.web.InjectorHolder;

import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: dylan
 * Date: Dec 6, 2010
 * Time: 10:29:52 PM
 * To change this template use File | Settings | File Templates.
 */
public class FilterOther implements DeckFilter, Serializable
{
    /**
     * TODO: find a cleaner way to inject filters
     */
    @Inject
    private SetService setService;

    public FilterOther()
    {
        InjectorHolder.getInjector().inject(this);
    }

    public DeckDescriptor filter(DeckDescriptor input)
    {
        DeckDescriptor result = new DeckDescriptor(input.getName());
        for (String section : input.getSections())
        {
            for (CardInDeck card : input.getCardsInSection(section))
            {
                CardInSet cis = setService.getCardInSet(card);
                if (cis != null)
                {
                    String type = cis.getType();
                    type = type.replace("Legendary ", "");
                    type = type.replace("Artifact ", "");
                    type = type.replace("Basic ", "");
                    if (!("Instant".equals(type)
                            || "Sorcery".equals(type)
                            || "Land".equals(type)
                            || "Basic Land".equals(type)
                            || "Creature".equals(type)
                            || "Creature".equals(type)
                            || "Artifact".equals(type)))
                    {
                        result.getCardsInSection(DeckDescriptor.SECTION_MAIN).add(new CardInDeck(card));
                    }
                }
            }
        }
        return result;
    }

}
